package org.goobs.mapping;

import java.util.HashMap;
import java.util.Map;

import org.goobs.database.DatabaseRow;

public class Location implements DatabaseRow{

	public static final String[] COLS = {"lat", "lon", "osm_node_id"};
	public static final String[] TYPES = {"DOUBLE", "DOUBLE", "INT"};
	public static final String[] INDEX = {"osm_node_id"};
	
	public static int NONE = -1;
	public static int VILLAGE = 0;
	public static int TOWN = 1;
	public static int CITY = 2;
	
	private int osmId;
	private double longitude;
	private double latitude;
	
	protected Location(){
		
	}
	
	protected Location(double longitude, double latitude, int osmId){
		recycle(longitude, latitude, osmId);
	}
	
	public void recycle(double longitude, double latitude, int osmId){
		this.osmId = osmId;
		this.longitude = longitude;
		this.latitude = latitude;
	}
	
	protected boolean isSettlement(String placeType){
		return placeType.equalsIgnoreCase("village") ||
		placeType.equalsIgnoreCase("town") ||
		placeType.equalsIgnoreCase("city");
	}
	
	public int getOSMId(){
		return osmId;
	}
	
	public double getLongitude(){
		return longitude;
	}
	
	public double getLatitude(){
		return latitude;
	}
	

	@Override
	public Map<String, Object> export() {
		Map <String, Object> export = new HashMap <String, Object> ();
		export.put("osm_node_id", osmId);
		export.put("lon", longitude);
		export.put("lat", latitude);
		return export;
	}

	@Override
	public void load(Map<String, Object> row) {
//		for(String key : row.keySet()){
//			System.out.println(key + " : " + row.get(key));
//		}
//		System.out.println();
		osmId = (Integer) row.get("osm_node_id");
		longitude = (Double) row.get("lon");
		latitude = (Double) row.get("lat");
	}
	
	
	
	protected static int toPlace(String name){
		if(name.equalsIgnoreCase("village")){
			return VILLAGE;
		}else if(name.equalsIgnoreCase("town")){
			return TOWN;
		}else if(name.equalsIgnoreCase("city")){
			return CITY;
		}else{
			return NONE;
		}
	}
	
	
}
